//****************************************************************
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   AssemblyFindQuery.java  $$
//* $$Revision:   1.0  $$
//* $$Author:   aponte  $$
//* $$Date:   Dec 10 2008 11:00:04  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import java.sql.Timestamp;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class AssemblyFindQuery implements CustomExpressionFactory {

	public Expression createExpression(ExpressionBuilder builder,
			Object[] parameters) {

		Timestamp fechaInicio = (Timestamp) parameters[0];
		Timestamp fechaFin = (Timestamp) parameters[1];
		Teesg01Plant teesg01Plant = (Teesg01Plant) parameters[2];
		
		// Added by LSPARACI
		
        // Teesp01Part teesp01Part = (Teesp01Part) parameters[3];
		// se reemplaza por lo siguiente, y se modifica parametros en  persistence-config
		String pclass  = (String) parameters[3];
		String pprefix = (String) parameters[4];
		String pbase   = (String) parameters[5];
		String psuffix = (String) parameters[6];
		// end LSPARACI
		
		Expression exp = null;

		exp = builder.get("pdr018PlantCodeC").equal(teesg01Plant);

/*
 * LSPARACI
 		exp = builder.get("teesp01Part").equal(teesp01Part);
*/ 		
		exp = exp.and(builder.get("pdr018AssyClassCodeC").equal(pclass));
		exp = exp.and(builder.get("pdr018AssyPrefixCodeC").equal(pprefix));
		exp = exp.and(builder.get("pdr018AssyBaseCodeC").equal(pbase));
		exp = exp.and(builder.get("pdr018AssySuffixCodeC").equal(psuffix));

		// comparo la vigencia del assembly y de la subparte
		exp = exp.and(builder.get("pdr018AssyInDateY").lessThan(fechaInicio));
		exp = exp.and(builder.get("pdr018AssyOutDateY").greaterThan(fechaFin));
/* LSPARACI
		exp = exp.and(builder.get("teesp01PartComp").get("eesp01PartInDateY")
				.lessThan(fechaInicio));
		exp = exp.and(builder.get("teesp01PartComp").get("eesp01PartOutDateY")
				.greaterThan(fechaFin));
*/
		return exp;
	}

}
